package com.sxm.yiwei.pinche;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshScrollView;
import com.sxm.yiwei.R;
import com.sxm.yiwei.activitis.AppManager;
import com.sxm.yiwei.adapters.pinche.PincheOrderListAdapter;
import com.sxm.yiwei.base.BaseFragment;
import com.sxm.yiwei.beans.pinche.Order;
import com.sxm.yiwei.constant.Common;
import com.sxm.yiwei.constant.Constant;
import com.sxm.yiwei.utils.DateUtil;
import com.sxm.yiwei.views.MyListview;

import java.util.ArrayList;

/**
 * Created by Administrator on 2017/10/28.
 */

public class PincheOrderFragment extends BaseFragment implements  AdapterView.OnItemClickListener {

    private static PincheOrderFragment mFragment;
    private MyListview listView;
    private int identity;
    private int order_type;
    private int go_type=Constant.LONG;
    private ArrayList<Order> beanList=new ArrayList<>();
    private View view;
    private int TAG=Constant.LONG;
    private PincheOrderListAdapter adapter;
    private RelativeLayout rl_building;
    private PullToRefreshScrollView refreshView;
    private int httpAction=Constant.DEFAULT;
    private int page=1;
    private int pageSize=5;
    private ImageView image;
    private int mPosition;
    private int failure_code;

    @Override
    protected int setContentView() {
        return R.layout.fragment_host_orders;
    }

    @Override
    protected void startLoad() {
        ScrollView scrollView = refreshView.getRefreshableView();
        scrollView.smoothScrollTo(0,0);
        Log.e("result","start:"+order_type+" "+go_type);
        httpAction=Constant.DEFAULT;
        getList();
           //getOrderList();//模拟数据
}

    private void getList() {
        JSONObject object = new JSONObject();
        object.put("pinServiceKinds",TAG+"");
        object.put("role",identity+"");
        object.put("pageNo",page+"");
        object.put("pageSize",pageSize+"");
        Log.d("pinServiceKinds",TAG+"");
        switch (order_type){
            case Constant.WAIT_PAY:
                httpGet(getActivity(), Common.HOST+Common.WAIT_PAY_LIST,object,identity+""+order_type+""+TAG);
                break;
            case Constant.WAIT_TAKE:
                httpGet(getActivity(), Common.HOST+Common.WAIT_TAKE_LIST,object,identity+""+order_type+""+TAG);
                break;
            case Constant.WAIT_SURVICE:
                object.put("orderStatus","1");
                httpGet(getActivity(), Common.HOST+Common.REST_ORDER_LIST,object,identity+""+order_type+""+TAG);
                break;
            case Constant.IN_SURVICE:
                object.put("orderStatus","2");
                httpGet(getActivity(), Common.HOST+Common.REST_ORDER_LIST,object,identity+""+order_type+""+TAG);
                break;
            case Constant.WAIT_FINISH:
                object.put("orderStatus","3");
                httpGet(getActivity(), Common.HOST+Common.REST_ORDER_LIST,object,identity+""+order_type+""+TAG);
                break;
            case Constant.FINISHED:
                object.put("orderStatus","4");
                httpGet(getActivity(), Common.HOST+Common.REST_ORDER_LIST,object,identity+""+order_type+""+TAG);
                break;
            case Constant.LOSS:
                object.put("orderStatus","5");
                httpGet(getActivity(), Common.HOST+Common.REST_ORDER_LIST,object,identity+""+order_type+""+TAG);
                break;
            case Constant.EXCEPTION:
                object.put("orderStatus","6");
                httpGet(getActivity(), Common.HOST+Common.REST_ORDER_LIST,object,identity+""+order_type+""+TAG);
                break;
        }
    }


    @Override
    protected void initData() {
        acceptIntent();
        initView();
        adapter = new PincheOrderListAdapter(getActivity(),beanList,identity,order_type,TAG);
        listView.setAdapter(adapter);
        listView.setOnItemClickListener(this);

        /*
        * 刷新监听
        * */
        refreshView.setMode(PullToRefreshBase.Mode.BOTH);
        refreshView.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2<ScrollView>() {
            @Override
            public void onPullDownToRefresh(final PullToRefreshBase<ScrollView> refreshView) {
                httpAction=Constant.REFRESH;
                page=1;
                refreshView.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        getList();
                        refreshView.onRefreshComplete();
                    }
                },2000);
            }

            @Override
            public void onPullUpToRefresh(final PullToRefreshBase<ScrollView> refreshView) {
                httpAction=Constant.LOAD_MORE;
                page++;
                refreshView.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        getList();
                        refreshView.onRefreshComplete();
                    }
                },2000);
            }
        });
        /*
        * 开始服务，开始售票，停止售票，取消订单，取消申诉,行程完结
        * */
        adapter.setOnStartService(new PincheOrderListAdapter.OnOrderHandleListener() {
            @Override
                public void onStartService(String order_id, String from,int position) {
                    mPosition=position;
                    JSONObject object = new JSONObject();
                    object.put("orderId",order_id);
                    httpPost(getActivity(),Common.HOST+Common.START_SERVICE,object,from);
                }

                @Override
                public void onStartSellTicket(String service_id, String isPermit, String from,int position) {
                    mPosition=position;
                    JSONObject object = new JSONObject();
                    object.put("serviceId",service_id);
                    if (isPermit.equals(Constant.YES+"")){
                        object.put("isPermit","0");
                    }else {
                        object.put("isPermit","1");

                    }
                    httpPost(getActivity(),Common.HOST+Common.START_END_SELL,object,from);
                }

                @Override
                public void onEndSellTicket(String service_id, String isPermit, String from,int position) {
                    mPosition=position;
                    JSONObject object = new JSONObject();
                    object.put("serviceId",service_id);
                    if (isPermit.equals(Constant.YES+"")){
                        object.put("isPermit","0");

                    }else {
                        object.put("isPermit","1");

                    }
                    httpPost(getActivity(),Common.HOST+Common.START_END_SELL,object,from);
                }

                @Override
                public void onCancelOrder(String type, String serviceStatus, String orderId,int position,String from) {
                     mPosition=position;
                    cancelOrder(type, serviceStatus, orderId, from);
                }

                @Override
                public void onCancelAppeal(String orderId, int position, String from) {
                    mPosition=position;
                    cancelAppealDialog(orderId,from);

                }

                @Override
                public void onRouteFinish(String role, String orderId,int position, String from) {
                    mPosition=position;
                    JSONObject object = new JSONObject();
                    object.put("role",role);
                    object.put("orderId",orderId);
                    httpPost(getActivity(),Common.HOST+Common.ROUTE_FINISH,object,from);
                }

                @Override
                public void onAlreadyInCarClick(String orderId, int position, String from) {
                    mPosition=position;
                    JSONObject object = new JSONObject();
                    object.put("orderId",orderId);
                    httpPost(getActivity(),Common.HOST+Common.ALREADY_IN_CAR,object,from);
                }

        });
        rl_building.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
            }
        });
    }

    private void initView() {
        if (view == null){
            view = getContentView();
        }
        image = (ImageView)view.findViewById(R.id.image);
        listView = (MyListview) view.findViewById(R.id.listView);
        refreshView = (PullToRefreshScrollView)view.findViewById(R.id.refresh_view);
        rl_building = (RelativeLayout)view.findViewById(R.id.rl_building);
    }

    /*
    * 接受参数
    * */
    private void acceptIntent() {
        Bundle bundle = getArguments();
        identity = bundle.getInt("identity");
        order_type = bundle.getInt("order_type");
        go_type = bundle.getInt("go_type");
        Log.d("initData",go_type+"");
        switch (go_type){
            case 0:
                TAG=Constant.LONG;
                break;
            case 1:
                TAG=Constant.CITY;
                break;
            case 2:
                TAG=Constant.TRAVEL;
                break;
            case 3:
                TAG=Constant.LONG_HURRY;
                break;
        }
    }

    /*
    * 取消订单
    * */
    private void cancelOrder(String type, String serviceStatus, String orderId, String from) {
        JSONObject object = new JSONObject();
        object.put("type",type);
        object.put("serviceStatus",serviceStatus);
        object.put("orderId",orderId);
        httpPost(getActivity(), Common.HOST+Common.CANCEL_ORDER,object,from);
    }

    @Override
    protected void stopLoad() {
        Log.i("result","stop:"+order_type+" "+go_type);
    }

    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
        Intent intent = null;
        Order order = beanList.get(i);
        if (identity==Constant.PASSENGER){
            intent = new Intent(getActivity(),PincheOrderDetailActivity.class);
        }else {
            intent=new Intent(getActivity(),PincheOrderDetailHostActivity.class);
        }
        intent.putExtra("order_type",order_type);
        intent.putExtra("go_type",TAG);
        intent.putExtra("order",order);
        intent.putExtra("position",i);
        intent.putExtra("order_id",order.getOrder_id());
        if (order_type==Constant.WAIT_PAY){
            if (order.getForm_way()==Constant.RELEASE){
                if (!TextUtils.isEmpty(order.getService_id())){
                    intent.putExtra("serviceId",order.getService_id());
                }else {
                    showToast("serviceId为空");
                    return;
                }
            }else {
                intent.putExtra("serviceId","");
            }
        }else if (order_type==Constant.WAIT_TAKE){
            if (!TextUtils.isEmpty(order.getService_id())){
                intent.putExtra("serviceId",order.getService_id());
            }else {
                showToast("serviceId为空");
                return;
            }
        }else {
            intent.putExtra("serviceId","");
        }

        startActivityForResult(intent,Constant.REQUEST_CODE);

    }

    @Override
    public void onSuccess(String result, String fromWhere) {
        super.onSuccess(result,fromWhere);
        com.alibaba.fastjson.JSONObject obj = JSON.parseObject(result);
        JSONObject data = obj.getJSONObject("data");
        if (!fromWhere.equals(Constant.START_SERVICE)&&!fromWhere.equals(Constant.START_SELL)&&!fromWhere.equals(Constant.END_SELL)&&!fromWhere.equals(Constant.CANCEL_ORDER)&&!fromWhere.equals(Constant.CANCEL_APPEAL)&&!fromWhere.equals(Constant.ROUTE_FINISHED)&&!fromWhere.equals(Constant.ALREADY_IN_CAR)){
            if (httpAction==Constant.DEFAULT||httpAction==Constant.REFRESH){
                beanList.clear();
            }

            if (fromWhere.equals("001")||fromWhere.equals("002")||fromWhere.equals("003")){//乘客待付款
                JSONArray mixList = data.getJSONArray("mix");
                for (int i = 0; i < mixList.size(); i++) {
                    Order order = new Order();
                    JSONObject object = mixList.getJSONObject(i);
                    //服务订单公共字段
                    order.setForm_way(Integer.parseInt(object.getString("type")));
                    order.setDepart_time(DateUtil.times(object.getLong("leaveOffTime")));
                    order.setPhone(object.getString("mobile"));
                    order.setStart_time(DateUtil.times(object.getLong("pinCreateTime")));
                    order.setEnd_place(object.getString("pinEndPoint"));
                    order.setSingle_money(object.getDouble("pinServiceAccount"));
                    order.setService_code(object.getString("pinServiceCode"));
                    order.setStyle(object.getIntValue("pinServiceKinds"));
                    order.setStart_place(object.getString("pinStartPoint"));
                    order.setTotal_money(object.getDouble("pinTotalAccount"));
                    order.setDistance(object.getDouble("pinTotalDistance"));
                    order.setService_id(object.getString("serviceId"));
                    order.setOrder_code(object.getString("orderCode"));
                    order.setIs_timeout(object.getIntValue("orderTimeOut"));
                    order.setWords(object.getString("pinLeaveWords"));

                    if (object.getString("type").equals("0")){//服务
                        order.setSeats(object.getIntValue("passerRequireSeats"));
                    }else {//订单
                        order.setOrder_id(object.getString("orderId"));
                        order.setSeats(object.getIntValue("ownerHasSeats"));
                        order.setIcon(object.getString("ownerAvatar"));
                        order.setOwnerId(object.getString("ownerId"));
                        order.setNickname(object.getString("ownerNickName"));
                        ArrayList<String> imgList = new ArrayList<>();
                        JSONArray list = object.getJSONArray("vehicleAvatarList");
                        for (int j = 0; j < list.size(); j++) {
                            String img = list.getString(j);
                            imgList.add(img);
                        }
                        order.setImgList(imgList);
                    }
                    beanList.add(order);
                }
            }else if (fromWhere.equals("011")||fromWhere.equals("012")||fromWhere.equals("013")){//乘客待接单
                JSONArray passerList = data.getJSONArray("passerList");
                for (int i = 0; i < passerList.size(); i++) {
                    Order order = new Order();
                    JSONObject object = passerList.getJSONObject(i);
                    order.setStart_time(DateUtil.times(object.getLong("pinCreateTime")));
                    order.setDepart_time(DateUtil.times(object.getLong("leaveOffTime")));
                    order.setPay_type(object.getIntValue("orderPayType"));
                    order.setSeats(object.getIntValue("passerRequireSeats"));

                    order.setEnd_place(object.getString("pinEndPoint"));
                    order.setWords(object.getString("pinLeaveWords"));

                    order.setService_code(object.getString("pinServiceCode"));
                    order.setStyle(object.getIntValue("pinServiceKinds"));
                    order.setStart_place(object.getString("pinStartPoint"));
                    order.setTotal_money(object.getDouble("pinTotalAccount"));
                    order.setDistance(object.getDouble("pinTotalDistance"));
                    order.setService_id(object.getString("serviceId"));
                    order.setPay_time(DateUtil.times(object.getLong("servicePayTime")));
                    order.setPhone(object.getString("userMobile"));
                    order.setOrder_code(object.getString("orderCode"));


                    beanList.add(order);
                }

            }else if (fromWhere.equals("021")||fromWhere.equals("022")||fromWhere.equals("023")){//乘客待服务(同订单异常)
                JSONArray ownerList = data.getJSONArray("ownerList");
                for (int i = 0; i < ownerList.size(); i++) {
                    Order order = new Order();
                    JSONObject object = ownerList.getJSONObject(i);
                    order.setDepart_time(DateUtil.times(object.getLong("leaveOffTime")));
                    order.setLeaveOffTime(object.getLong("leaveOffTime"));
                    order.setOrder_code(object.getString("orderCode"));
                    order.setOrder_id(object.getString("orderId"));
                    order.setPay_time(DateUtil.times(object.getLong("orderPayTime")));
                    order.setPay_type(object.getIntValue("orderPayType"));
                    order.setIs_timeout(object.getIntValue("orderTimeOut"));
                    order.setIcon(object.getString("ownerAvatar"));
                    order.setSeats(object.getIntValue("passerRequireSeats"));
                    order.setPhone(object.getString("mobile"));
                    order.setOwnerId(object.getString("ownerId"));
                    order.setNickname(object.getString("ownerNickName"));
                    order.setWho_created(object.getIntValue("orderCreateBy"));
                    order.setStart_time(DateUtil.times(object.getLong("pinCreateTime")));
                    order.setEnd_place(object.getString("pinEndPoint"));
                    order.setWords(object.getString("pinLeaveWords"));
                    order.setLoss_money(object.getDouble("pinLoseAccount"));
                    order.setSingle_money(object.getDouble("pinServiceAccount"));

                    order.setService_code(object.getString("pinServiceCode"));
                    order.setStyle(object.getIntValue("pinServiceKinds"));
                    order.setStart_place(object.getString("pinStartPoint"));
                    order.setTotal_money(object.getDouble("pinTotalAccount"));
                    order.setDistance(object.getDouble("pinTotalDistance"));
                    order.setVehicle_type(object.getIntValue("vehicleType"));
                    order.setService_id(object.getString("serviceId"));
                    ArrayList<String> imgList = new ArrayList<>();
                    JSONArray list = object.getJSONArray("vehicleAvatarList");
                    for (int j = 0; j < list.size(); j++) {
                        String img = list.getString(j);
                        imgList.add(img);
                    }
                    order.setImgList(imgList);

                    beanList.add(order);
                }

            }else if (fromWhere.equals("031")||fromWhere.equals("032")||fromWhere.equals("033")){//乘客服务中
                JSONArray ownerList = data.getJSONArray("ownerList");
                for (int i = 0; i < ownerList.size(); i++) {
                    Order order = new Order();
                    JSONObject object = ownerList.getJSONObject(i);
                    order.setDepart_time(DateUtil.times(object.getLong("leaveOffTime")));
                    order.setPhone(object.getString("mobile"));
                    order.setOrder_code(object.getString("orderCode"));
                    order.setOrder_id(object.getString("orderId"));
                    order.setPay_time(DateUtil.times(object.getLong("orderPayTime")));
                    order.setPay_type(object.getIntValue("orderPayType"));
                    order.setIs_timeout(object.getIntValue("orderTimeOut"));
                    order.setIcon(object.getString("ownerAvatar"));
                    order.setOwnerId(object.getString("ownerId"));
                    order.setNickname(object.getString("ownerNickName"));
                    order.setStart_time(DateUtil.times(object.getLong("pinCreateTime")));
                    order.setEnd_place(object.getString("pinEndPoint"));
                    order.setWords(object.getString("pinLeaveWords"));
                    order.setService_code(object.getString("pinServiceCode"));
                    order.setStyle(object.getIntValue("pinServiceKinds"));
                    order.setStart_place(object.getString("pinStartPoint"));
                    order.setTotal_money(object.getDouble("pinTotalAccount"));
                    order.setDistance(object.getDouble("pinTotalDistance"));
                    order.setService_id(object.getString("serviceId"));
                    order.setVehicle_type(object.getIntValue("vehicleType"));
                    order.setWho_created(object.getIntValue("orderCreateBy"));
                    order.setIs_in_car(object.getIntValue("isPasserOn"));
                    ArrayList<String> imgList = new ArrayList<>();
                    JSONArray list = object.getJSONArray("vehicleAvatarList");
                    for (int j = 0; j < list.size(); j++) {
                        String img = list.getString(j);
                        imgList.add(img);
                    }
                    order.setImgList(imgList);
                    order.setSeats(object.getIntValue("passerRequireSeats"));
                    beanList.add(order);
                }

            }else if (fromWhere.equals("041")||fromWhere.equals("042")||fromWhere.equals("043")){//乘客待完结

                JSONArray ownerList = data.getJSONArray("ownerList");
                for (int i = 0; i < ownerList.size(); i++) {
                    Order order = new Order();
                    JSONObject object = ownerList.getJSONObject(i);
                    order.setDepart_time(DateUtil.times(object.getLong("leaveOffTime")));
                    order.setPhone(object.getString("mobile"));
                    order.setOrder_code(object.getString("orderCode"));
                    order.setOrder_id(object.getString("orderId"));
                    order.setPay_time(DateUtil.times(object.getLong("orderPayTime")));
                    order.setPay_type(object.getIntValue("orderPayType"));
                    order.setIs_timeout(object.getIntValue("orderTimeOut"));
                    order.setIcon(object.getString("ownerAvatar"));
                    order.setOwnerId(object.getString("ownerId"));
                    order.setNickname(object.getString("ownerNickName"));
                    order.setStart_time(DateUtil.times(object.getLong("pinCreateTime")));
                    order.setEnd_place(object.getString("pinEndPoint"));
                    order.setWords(object.getString("pinLeaveWords"));
                    order.setService_code(object.getString("pinServiceCode"));
                    order.setStyle(object.getIntValue("pinServiceKinds"));
                    order.setStart_place(object.getString("pinStartPoint"));
                    order.setTotal_money(object.getDouble("pinTotalAccount"));
                    order.setWho_created(object.getIntValue("orderCreateBy"));
                    order.setDistance(object.getDouble("pinTotalDistance"));
                    order.setService_id(object.getString("serviceId"));
                    order.setVehicle_type(object.getIntValue("vehicleType"));
                    //1 完结 0 未完结
                    if (object.getIntValue("ownerEndStatus")==0&&object.getIntValue("passerEndStatus")==1){
                        order.setIs_finished(Constant.HOST_FINISHED_PASSENGER_NO);
                    }else if (object.getIntValue("ownerEndStatus")==1&&object.getIntValue("passerEndStatus")==0){
                        order.setIs_finished(Constant.PASSENGER_FINISHED_HOST_NO);
                    }else {
                        showToast("完结状态异常");
                    }
                    ArrayList<String> imgList = new ArrayList<>();
                    JSONArray list = object.getJSONArray("vehicleAvatarList");
                    for (int j = 0; j < list.size(); j++) {
                        String img = list.getString(j);
                        imgList.add(img);
                    }
                    order.setImgList(imgList);
                    order.setSeats(object.getIntValue("passerRequireSeats"));
                    beanList.add(order);
                }
            }else if (fromWhere.equals("051")||fromWhere.equals("052")||fromWhere.equals("053")){//乘客已完结
                JSONArray ownerList = data.getJSONArray("ownerList");
                for (int i = 0; i < ownerList.size(); i++) {
                    Order order = new Order();
                    JSONObject object = ownerList.getJSONObject(i);
                    order.setDepart_time(DateUtil.times(object.getLong("leaveOffTime")));
                    order.setPhone(object.getString("mobile"));
                    order.setOrder_code(object.getString("orderCode"));
                    order.setOrder_id(object.getString("orderId"));
                    order.setPay_time(DateUtil.times(object.getLong("orderPayTime")));
                    order.setPay_type(object.getIntValue("orderPayType"));
                    order.setIs_timeout(object.getIntValue("orderTimeOut"));
                    order.setIcon(object.getString("ownerAvatar"));
                    order.setOwnerId(object.getString("ownerId"));
                    order.setNickname(object.getString("ownerNickName"));
                    order.setStart_time(DateUtil.times(object.getLong("pinCreateTime")));
                    order.setEnd_place(object.getString("pinEndPoint"));
                    order.setWords(object.getString("pinLeaveWords"));
                    order.setService_code(object.getString("pinServiceCode"));
                    order.setStyle(object.getIntValue("pinServiceKinds"));
                    order.setStart_place(object.getString("pinStartPoint"));
                    order.setTotal_money(object.getDouble("pinTotalAccount"));
                    order.setDistance(object.getDouble("pinTotalDistance"));
                    order.setService_id(object.getString("serviceId"));
                    order.setVehicle_type(object.getIntValue("vehicleType"));
                    order.setWho_created(object.getIntValue("orderCreateBy"));
                    ArrayList<String> imgList = new ArrayList<>();
                    JSONArray list = object.getJSONArray("vehicleAvatarList");
                    for (int j = 0; j < list.size(); j++) {
                        String img = list.getString(j);
                        imgList.add(img);
                    }
                    order.setImgList(imgList);
                    order.setSeats(object.getIntValue("passerRequireSeats"));
                    beanList.add(order);
                }
            }else if (fromWhere.equals("061")||fromWhere.equals("062")||fromWhere.equals("063")){//乘客爽约单
                JSONArray ownerList = data.getJSONArray("ownerList");
                for (int i = 0; i < ownerList.size(); i++) {
                    Order order = new Order();
                    JSONObject object = ownerList.getJSONObject(i);
                    order.setDepart_time(DateUtil.times(object.getLong("leaveOffTime")));
                    order.setPhone(object.getString("mobile"));
                    order.setOrder_code(object.getString("orderCode"));
                    order.setOrder_id(object.getString("orderId"));
                    order.setPay_time(DateUtil.times(object.getLong("orderPayTime")));
                    order.setPay_type(object.getIntValue("orderPayType"));
                    order.setIs_timeout(object.getIntValue("orderTimeOut"));
                    order.setIcon(object.getString("ownerAvatar"));
                    order.setOwnerId(object.getString("ownerId"));
                    order.setNickname(object.getString("ownerNickName"));
                    order.setSeats(object.getIntValue("passerRequireSeats"));

                    order.setStart_time(DateUtil.times(object.getLong("pinCreateTime")));
                    order.setEnd_place(object.getString("pinEndPoint"));
                    order.setWords(object.getString("pinLeaveWords"));
                    order.setLoss_money(object.getDouble("pinLoseAccount"));
                    order.setSingle_money(object.getDouble("pinServiceAccount"));
                    order.setService_code(object.getString("pinServiceCode"));
                    order.setStyle(object.getIntValue("pinServiceKinds"));
                    order.setStart_place(object.getString("pinStartPoint"));
                    order.setTotal_money(object.getDouble("pinTotalAccount"));
                    order.setDistance(object.getDouble("pinTotalDistance"));
                    order.setVehicle_type(object.getIntValue("vehicleType"));
                    order.setService_id(object.getString("serviceId"));
                    order.setWho_created(object.getIntValue("orderCreateBy"));
                    ArrayList<String> imgList = new ArrayList<>();
                    JSONArray list = object.getJSONArray("vehicleAvatarList");
                    for (int j = 0; j < list.size(); j++) {
                        String img = list.getString(j);
                        imgList.add(img);
                    }
                    order.setImgList(imgList);

                    //爽约相关字段
                    /*
                    *  private Integer loseTarget; //爽约对象；0：乘客；1：车主

                         private Integer indemnifyIsPaid; //是否赔付；1：赔付；0：未赔付（免爽约金)

                        private String indemnifyMatter; //赔付原因

                        private Double indemnifyAmount; //赔付金额

                        private Double passerQuitAmount; //乘客返还金额

                         private Double ownerQuitAmount; //车主返还金额

                    * */
                    order.setIs_return(object.getIntValue("indemnifyIsPaid"));//是否赔付
                    if (object.getIntValue("loseTarget")==Constant.PASSENGER){
                        order.setWho_return(Constant.ME);//赔付对象
                    }else {
                        order.setWho_return(Constant.NOT_ME);//赔付对象
                    }
                    order.setWhy_return(object.getString("indemnifyMatter"));
                    order.setPayment(object.getDouble("indemnifyAmount"));
                    order.setPasserPayback(object.getDouble("passerQuitAmount"));
                    order.setOwnerPayback(object.getDouble("ownerQuitAmount"));

                    beanList.add(order);
                }

            }else if (fromWhere.equals("071")||fromWhere.equals("072")||fromWhere.equals("073")){//乘客订单异常

                JSONArray ownerList = data.getJSONArray("ownerList");
                for (int i = 0; i < ownerList.size(); i++) {
                    Order order = new Order();
                    JSONObject object = ownerList.getJSONObject(i);
                    order.setIs_reply(object.getIntValue("complaintHandleStatus"));
                    order.setDepart_time(DateUtil.times(object.getLong("leaveOffTime")));
                    order.setOrder_code(object.getString("orderCode"));
                    order.setOrder_id(object.getString("orderId"));
                    order.setPay_time(DateUtil.times(object.getLong("orderPayTime")));
                    order.setPay_type(object.getIntValue("orderPayType"));
                    order.setIs_timeout(object.getIntValue("orderTimeOut"));
                    order.setIcon(object.getString("ownerAvatar"));
                    order.setSeats(object.getIntValue("passerRequireSeats"));
                    order.setPhone(object.getString("mobile"));
                    order.setOwnerId(object.getString("ownerId"));
                    order.setNickname(object.getString("ownerNickName"));

                    order.setStart_time(DateUtil.times(object.getLong("pinCreateTime")));
                    order.setEnd_place(object.getString("pinEndPoint"));
                    order.setWords(object.getString("pinLeaveWords"));
                    order.setLoss_money(object.getDouble("pinLoseAccount"));
                    order.setService_code(object.getString("pinServiceCode"));
                    order.setStyle(object.getIntValue("pinServiceKinds"));
                    order.setStart_place(object.getString("pinStartPoint"));
                    order.setTotal_money(object.getDouble("pinTotalAccount"));
                    order.setDistance(object.getDouble("pinTotalDistance"));
                    order.setVehicle_type(object.getIntValue("vehicleType"));
                    order.setService_id(object.getString("serviceId"));
                    order.setWho_created(object.getIntValue("orderCreateBy"));
                    ArrayList<String> imgList = new ArrayList<>();
                    JSONArray list = object.getJSONArray("vehicleAvatarList");
                    for (int j = 0; j < list.size(); j++) {
                        String img = list.getString(j);
                        imgList.add(img);
                    }
                    order.setImgList(imgList);

                    beanList.add(order);
                }



                ///////////////////////////////////////////////////////////////////////////////
            }else if (fromWhere.equals("101")||fromWhere.equals("102")||fromWhere.equals("103")){//车主待付款
                JSONArray mixList = data.getJSONArray("mix");
                for (int i = 0; i < mixList.size(); i++) {
                    Order order = new Order();
                    JSONObject object = mixList.getJSONObject(i);
                    //服务订单公共字段
                    order.setForm_way(Integer.parseInt(object.getString("type")));
                    order.setDepart_time(DateUtil.times(object.getLong("leaveOffTime")));
                    order.setPhone(object.getString("mobile"));
                    order.setStart_time(DateUtil.times(object.getLong("pinCreateTime")));
                    order.setEnd_place(object.getString("pinEndPoint"));
                    order.setService_code(object.getString("pinServiceCode"));
                    order.setStyle(object.getIntValue("pinServiceKinds"));
                    order.setStart_place(object.getString("pinStartPoint"));
                    order.setDistance(object.getDouble("pinTotalDistance"));
                    order.setService_id(object.getString("serviceId"));
                    order.setOrder_id(object.getString("orderId"));
                    order.setOrder_code(object.getString("orderCode"));
                    order.setIs_timeout(object.getIntValue("orderTimeOut"));
                    order.setWords(object.getString("pinLeaveWords"));
                    order.setLoss_money(object.getDouble("pinLoseAccount"));
                    order.setTotal_money(object.getDouble("pinTotalAccount"));

                    if (object.getString("type").equals("0")) {//服务
                        order.setSeats(object.getIntValue("ownerHasSeats"));
                        order.setVehicle_type(object.getIntValue("vehicleType"));
                        order.setSingle_money(object.getDouble("pinServiceAccount"));
                    } else {//订单
                        order.setNickname(object.getString("ownerNickName"));
                        order.setIcon(object.getString("passerAvatar"));
                        order.setSeats(object.getIntValue("passerRequireSeats"));
                    }
                    beanList.add(order);
                }
            }else if (fromWhere.equals("111")||fromWhere.equals("112")||fromWhere.equals("113")){//车主待接单
                JSONArray ownerList = data.getJSONArray("ownerList");
                for (int i = 0; i < ownerList.size(); i++) {
                    Order order = new Order();
                    JSONObject object = ownerList.getJSONObject(i);
                    order.setDepart_time(DateUtil.times(object.getLong("leaveOffTime")));
                    order.setOrder_id(object.getString("orderId"));
                    order.setPay_type(object.getIntValue("orderPayType"));
                    order.setRest_tickets(object.getIntValue("ownerHasSeats"));//剩余座位
                    order.setPhone(object.getString("ownerMobile"));
                    order.setOrder_code(object.getString("orderCode"));
                    order.setStart_time(DateUtil.times(object.getLong("pinCreateTime")));
                    order.setEnd_place(object.getString("pinEndPoint"));
                    order.setWords(object.getString("pinLeaveWords"));
                    order.setLoss_money(object.getDouble("pinLoseAccount"));
                    order.setSingle_money(object.getDouble("pinServiceAccount"));

                    order.setService_code(object.getString("pinServiceCode"));
                    order.setStyle(object.getIntValue("pinServiceKinds"));
                    order.setStart_place(object.getString("pinStartPoint"));
                    order.setTotal_money(object.getDouble("pinTotalAccount"));
                    order.setDistance(object.getDouble("pinTotalDistance"));
                    order.setService_id(object.getString("serviceId"));
                    order.setPay_time(DateUtil.times(object.getLong("servicePayTime")));
                    order.setSeats(object.getIntValue("ownerTotalSeats"));

                    if (object.getIntValue("pinSalePermit")==1){
                        order.setIs_sale_start(Constant.YES);
                    }else {
                        order.setIs_sale_start(Constant.NO);

                    }


                    beanList.add(order);
                }


            }else if (fromWhere.equals("121")||fromWhere.equals("122")||fromWhere.equals("123")){//车主待服务
                JSONArray passerList = data.getJSONArray("passerList");
                for (int i = 0; i < passerList.size(); i++) {
                    Order order = new Order();
                    JSONObject object = passerList.getJSONObject(i);
                    order.setDepart_time(DateUtil.times(object.getLong("leaveOffTime")));
                    order.setLeaveOffTime(object.getLong("leaveOffTime"));
                    order.setOrder_code(object.getString("orderCode"));
                    order.setOrder_id(object.getString("orderId"));
                    order.setIs_timeout(object.getIntValue("orderTimeOut"));
                    order.setOwnerId(object.getString("ownerId"));
                    order.setPay_time(DateUtil.times(object.getLong("orderPayTime")));
                    order.setIcon(object.getString("passerAvatar"));
                    order.setPhone(object.getString("mobile"));
                    order.setNickname(object.getString("passerNickName"));
                    order.setSeats(object.getIntValue("passerRequireSeats"));
                    order.setStart_time(DateUtil.times(object.getLong("pinCreateTime")));
                    order.setEnd_place(object.getString("pinEndPoint"));
                    order.setWords(object.getString("pinLeaveWords"));
                    order.setLoss_money(object.getDouble("pinLoseAccount"));//总价
                    order.setService_code(object.getString("pinServiceCode"));
                    order.setStyle(object.getIntValue("pinServiceKinds"));
                    order.setStart_place(object.getString("pinStartPoint"));
                    order.setDistance(object.getDouble("pinTotalDistance"));
                    order.setTotal_money(object.getDouble("pinTotalAccount"));
                    order.setWho_created(object.getIntValue("orderCreateBy"));
                    order.setService_id(object.getString("serviceId"));
                    ArrayList<String> imgList = new ArrayList<>();
                    JSONArray list = object.getJSONArray("vehicleAvatarList");
                    for (int j = 0; j < list.size(); j++) {
                        String img = list.getString(j);
                        imgList.add(img);
                    }
                    order.setImgList(imgList);

                    beanList.add(order);
                }
            }else if (fromWhere.equals("131")||fromWhere.equals("132")||fromWhere.equals("133")){//车主服务中
                JSONArray passerList = data.getJSONArray("passerList");
                for (int i = 0; i < passerList.size(); i++) {
                    Order order = new Order();
                    JSONObject object = passerList.getJSONObject(i);
                    order.setDepart_time(DateUtil.times(object.getLong("leaveOffTime")));
                    order.setPhone(object.getString("mobile"));
                    order.setOrder_code(object.getString("orderCode"));
                    order.setOrder_id(object.getString("orderId"));
                    order.setPay_time(DateUtil.times(object.getLong("orderPayTime")));
                    order.setPay_type(object.getIntValue("orderPayType"));
                    order.setIs_timeout(object.getIntValue("orderTimeOut"));
                    order.setOwnerId(object.getString("ownerId"));
                    order.setIcon(object.getString("passerAvatar"));
                    order.setNickname(object.getString("passerNickName"));
                    order.setSeats(object.getIntValue("passerRequireSeats"));
                    order.setStart_time(DateUtil.times(object.getLong("pinCreateTime")));
                    order.setEnd_place(object.getString("pinEndPoint"));
                    order.setWords(object.getString("pinLeaveWords"));
                    order.setLoss_money(object.getDouble("pinLoseAccount"));
                    order.setService_code(object.getString("pinServiceCode"));
                    order.setStyle(object.getIntValue("pinServiceKinds"));
                    order.setStart_place(object.getString("pinStartPoint"));
                    order.setDistance(object.getDouble("pinTotalDistance"));
                    order.setService_id(object.getString("serviceId"));
                    order.setTotal_money(object.getDouble("pinTotalAccount"));
                    order.setWho_created(object.getIntValue("orderCreateBy"));
                    ArrayList<String> imgList = new ArrayList<>();
                    JSONArray list = object.getJSONArray("vehicleAvatarList");
                    for (int j = 0; j < list.size(); j++) {
                        String img = list.getString(j);
                        imgList.add(img);
                    }
                    order.setImgList(imgList);

                    beanList.add(order);
                }

            }else if (fromWhere.equals("141")||fromWhere.equals("142")||fromWhere.equals("143")){//车主待完结
                JSONArray passerList = data.getJSONArray("passerList");
                for (int i = 0; i < passerList.size(); i++) {
                    Order order = new Order();
                    JSONObject object = passerList.getJSONObject(i);
                    order.setDepart_time(DateUtil.times(object.getLong("leaveOffTime")));
                    order.setPhone(object.getString("mobile"));
                    order.setOrder_code(object.getString("orderCode"));
                    order.setOrder_id(object.getString("orderId"));
                    order.setPay_time(DateUtil.times(object.getLong("orderPayTime")));
                    order.setPay_type(object.getIntValue("orderPayType"));
                    order.setIs_timeout(object.getIntValue("orderTimeOut"));
                    order.setOwnerId(object.getString("ownerId"));
                    order.setIcon(object.getString("passerAvatar"));
                    order.setNickname(object.getString("passerNickName"));
                    order.setSeats(object.getIntValue("passerRequireSeats"));
                    order.setStart_time(DateUtil.times(object.getLong("pinCreateTime")));
                    order.setEnd_place(object.getString("pinEndPoint"));
                    order.setWords(object.getString("pinLeaveWords"));
                    order.setLoss_money(object.getDouble("pinLoseAccount"));
                    order.setService_code(object.getString("pinServiceCode"));
                    order.setStyle(object.getIntValue("pinServiceKinds"));
                    order.setStart_place(object.getString("pinStartPoint"));
                    order.setDistance(object.getDouble("pinTotalDistance"));
                    order.setService_id(object.getString("serviceId"));
                    order.setTotal_money(object.getDouble("pinTotalAccount"));
                    order.setWho_created(object.getIntValue("orderCreateBy"));
                    //1 完结 0 未完结
                    if (object.getIntValue("ownerEndStatus")==0&&object.getIntValue("passerEndStatus")==1){
                        order.setIs_finished(Constant.HOST_FINISHED_PASSENGER_NO);
                    }else if (object.getIntValue("ownerEndStatus")==1&&object.getIntValue("passerEndStatus")==0){
                        order.setIs_finished(Constant.PASSENGER_FINISHED_HOST_NO);
                    }else {
                        showToast("完结状态异常");
                    }
                    ArrayList<String> imgList = new ArrayList<>();
                    JSONArray list = object.getJSONArray("vehicleAvatarList");
                    for (int j = 0; j < list.size(); j++) {
                        String img = list.getString(j);
                        imgList.add(img);
                    }
                    order.setImgList(imgList);

                    beanList.add(order);
                }

            }else if (fromWhere.equals("151")||fromWhere.equals("152")||fromWhere.equals("153")){//车主已完结
                JSONArray passerList = data.getJSONArray("passerList");
                for (int i = 0; i < passerList.size(); i++) {
                    Order order = new Order();
                    JSONObject object = passerList.getJSONObject(i);
                    order.setDepart_time(DateUtil.times(object.getLong("leaveOffTime")));
                    order.setPhone(object.getString("mobile"));
                    order.setOrder_code(object.getString("orderCode"));
                    order.setOrder_id(object.getString("orderId"));
                    order.setPay_time(DateUtil.times(object.getLong("orderPayTime")));
                    order.setPay_type(object.getIntValue("orderPayType"));
                    order.setIs_timeout(object.getIntValue("orderTimeOut"));
                    order.setOwnerId(object.getString("ownerId"));
                    order.setIcon(object.getString("passerAvatar"));
                    order.setNickname(object.getString("passerNickName"));
                    order.setSeats(object.getIntValue("passerRequireSeats"));
                    order.setStart_time(DateUtil.times(object.getLong("pinCreateTime")));
                    order.setEnd_place(object.getString("pinEndPoint"));
                    order.setWords(object.getString("pinLeaveWords"));
                    order.setLoss_money(object.getDouble("pinLoseAccount"));
                    order.setService_code(object.getString("pinServiceCode"));
                    order.setStyle(object.getIntValue("pinServiceKinds"));
                    order.setStart_place(object.getString("pinStartPoint"));
                    order.setDistance(object.getDouble("pinTotalDistance"));
                    order.setService_id(object.getString("serviceId"));
                    order.setWho_created(object.getIntValue("orderCreateBy"));
                    order.setTotal_money(object.getDouble("pinTotalAccount"));
                    ArrayList<String> imgList = new ArrayList<>();
                    JSONArray list = object.getJSONArray("vehicleAvatarList");
                    for (int j = 0; j < list.size(); j++) {
                        String img = list.getString(j);
                        imgList.add(img);
                    }
                    order.setImgList(imgList);

                    beanList.add(order);
                }
            }else if (fromWhere.equals("161")||fromWhere.equals("162")||fromWhere.equals("163")){//车主爽约单
                JSONArray passerList = data.getJSONArray("passerList");
                for (int i = 0; i < passerList.size(); i++) {
                    Order order = new Order();
                    JSONObject object = passerList.getJSONObject(i);
                    order.setDepart_time(DateUtil.times(object.getLong("leaveOffTime")));
                    order.setPhone(object.getString("mobile"));
                    order.setOrder_code(object.getString("orderCode"));
                    order.setOrder_id(object.getString("orderId"));
                    order.setPay_time(DateUtil.times(object.getLong("orderPayTime")));
                    order.setPay_type(object.getIntValue("orderPayType"));
                    order.setIs_timeout(object.getIntValue("orderTimeOut"));
                    order.setOwnerId(object.getString("ownerId"));
                    order.setIcon(object.getString("passerAvatar"));
                    order.setNickname(object.getString("passerNickName"));
                    order.setSeats(object.getIntValue("passerRequireSeats"));
                    order.setStart_time(DateUtil.times(object.getLong("pinCreateTime")));
                    order.setEnd_place(object.getString("pinEndPoint"));
                    order.setWords(object.getString("pinLeaveWords"));
                    order.setLoss_money(object.getDouble("pinLoseAccount"));
                    order.setService_code(object.getString("pinServiceCode"));
                    order.setStyle(object.getIntValue("pinServiceKinds"));
                    order.setStart_place(object.getString("pinStartPoint"));
                    order.setDistance(object.getDouble("pinTotalDistance"));
                    order.setService_id(object.getString("serviceId"));
                    order.setWho_created(object.getIntValue("orderCreateBy"));
                    order.setTotal_money(object.getDouble("pinTotalAccount"));
                    ArrayList<String> imgList = new ArrayList<>();
                    JSONArray list = object.getJSONArray("vehicleAvatarList");
                    for (int j = 0; j < list.size(); j++) {
                        String img = list.getString(j);
                        imgList.add(img);
                    }
                    order.setImgList(imgList);

                    //爽约相关字段
                    /*
                    *  private Integer loseTarget; //爽约对象；0：乘客；1：车主

                         private Integer indemnifyIsPaid; //是否赔付；1：赔付；0：未赔付（免爽约金)

                        private String indemnifyMatter; //赔付原因

                        private Double indemnifyAmount; //赔付金额

                        private Double passerQuitAmount; //乘客返还金额

                         private Double ownerQuitAmount; //车主返还金额

                    * */
                    order.setIs_return(object.getIntValue("indemnifyIsPaid"));//是否赔付
                    if (object.getIntValue("loseTarget")==Constant.PASSENGER){
                        order.setWho_return(Constant.NOT_ME);//赔付对象
                    }else {
                        order.setWho_return(Constant.ME);//赔付对象
                    }
                    order.setWhy_return(object.getString("indemnifyMatter"));
                    order.setPayment(object.getDouble("indemnifyAmount"));
                    order.setPasserPayback(object.getDouble("passerQuitAmount"));
                    order.setOwnerPayback(object.getDouble("ownerQuitAmount"));

                    beanList.add(order);
                }

            }else if (fromWhere.equals("171")||fromWhere.equals("172")||fromWhere.equals("173")){//车主订单异常
                JSONArray passerList = data.getJSONArray("passerList");
                for (int i = 0; i < passerList.size(); i++) {
                    Order order = new Order();
                    JSONObject object = passerList.getJSONObject(i);
                    order.setIs_reply(object.getIntValue("complaintHandleStatus"));
                    order.setDepart_time(DateUtil.times(object.getLong("leaveOffTime")));
                    order.setPhone(object.getString("mobile"));
                    order.setOrder_code(object.getString("orderCode"));
                    order.setOrder_id(object.getString("orderId"));
                    order.setPay_time(DateUtil.times(object.getLong("orderPayTime")));
                    order.setPay_type(object.getIntValue("orderPayType"));
                    order.setIs_timeout(object.getIntValue("orderTimeOut"));
                    order.setOwnerId(object.getString("ownerId"));
                    order.setIcon(object.getString("passerAvatar"));
                    order.setNickname(object.getString("passerNickName"));
                    order.setSeats(object.getIntValue("passerRequireSeats"));
                    order.setStart_time(DateUtil.times(object.getLong("pinCreateTime")));
                    order.setEnd_place(object.getString("pinEndPoint"));
                    order.setWords(object.getString("pinLeaveWords"));
                    order.setLoss_money(object.getDouble("pinLoseAccount"));
                    order.setService_code(object.getString("pinServiceCode"));
                    order.setStyle(object.getIntValue("pinServiceKinds"));
                    order.setStart_place(object.getString("pinStartPoint"));
                    order.setDistance(object.getDouble("pinTotalDistance"));
                    order.setService_id(object.getString("serviceId"));
                    order.setWho_created(object.getIntValue("orderCreateBy"));
                    order.setTotal_money(object.getDouble("pinTotalAccount"));
                    ArrayList<String> imgList = new ArrayList<>();
                    JSONArray list = object.getJSONArray("vehicleAvatarList");
                    for (int j = 0; j < list.size(); j++) {
                        String img = list.getString(j);
                        imgList.add(img);
                    }
                    order.setImgList(imgList);

                    beanList.add(order);
                }
            }

        }else if (fromWhere.equals(Constant.START_SERVICE)){//开始服务
            showToast("开始服务");
            beanList.remove(mPosition);

        }else if (fromWhere.equals(Constant.START_SELL)){
            Order order = beanList.get(mPosition);
            order.setIs_sale_start(Constant.YES);
            beanList.remove(mPosition);
            beanList.add(mPosition,order);

        }else if (fromWhere.equals(Constant.END_SELL)){
            Order order = beanList.get(mPosition);
            order.setIs_sale_start(Constant.NO);
            beanList.remove(mPosition);
            beanList.add(mPosition,order);

        }else if (fromWhere.equals(Constant.CANCEL_ORDER)){
            beanList.remove(mPosition);
        }else if (fromWhere.equals(Constant.CANCEL_APPEAL)){
            beanList.remove(mPosition);
        }else if (fromWhere.equals(Constant.ROUTE_FINISHED)){//不用区分时服务中行程完结还是待完结行程完结，都是订单状态发生变化
            beanList.remove(mPosition);
        }else if (fromWhere.equals(Constant.ALREADY_IN_CAR)){
            showToast("我已上车调用成功");
            Order order = beanList.get(mPosition);
            order.setIs_in_car(Constant.YES);
            beanList.remove(mPosition);
            beanList.add(mPosition,order);
        }

        adapter.notifyDataSetChanged();
        if (beanList.size()==0){
            rl_building.setVisibility(View.VISIBLE);
            refreshView.setVisibility(View.GONE);
        }else {
            rl_building.setVisibility(View.GONE);
            refreshView.setVisibility(View.VISIBLE);
        }

    }

    @Override
    public void onError(Throwable ex) {
        super.onError(ex);
    }

    @Override
    public void onSuccessError(String result, String fromWhere) {
        super.onSuccessError(result, fromWhere);
    }

    /*
    * 模拟数据
    * */
    private void getOrderList() {
        if (httpAction==Constant.DEFAULT||httpAction==Constant.REFRESH){
            beanList.clear();
        }
        for (int i = 0; i <page*pageSize ; i++) {
            Order order = new Order();
            if (identity== Constant.PASSENGER){
                if (i<3){
                    order.setVehicle_type(Constant.BUS);
                }else {
                    order.setVehicle_type(Constant.PRIVATE_CAR);
                }
                switch (order_type){
                    case Constant.WAIT_PAY:
                        if(TAG!=Constant.LONG_HURRY){
                            if (i<3){
                                order.setForm_way(Constant.RELEASE);
                                order.setIs_published(Constant.NO);
                            }else {
                                order.setForm_way(Constant.BUY);
                                order.setIs_bought(Constant.NO);
                            }
                        }else {
                            if (i<3){
                               order.setIs_timeout(Constant.YES);
                            }else if (i>=3&&i<6){
                                order.setIs_timeout(Constant.NO);
                                order.setForm_way(Constant.RELEASE);
                            }else {
                                order.setForm_way(Constant.BUY);
                                order.setIs_bought(Constant.NO);
                            }
                        }
                        break;
                    case Constant.WAIT_TAKE:
                        if(TAG!=Constant.LONG_HURRY){
                            if (i<3){
                                order.setIs_timeout(Constant.NO);
                                order.setForm_way(Constant.RELEASE);
                            }else {
                                order.setIs_timeout(Constant.YES);
                                order.setForm_way(Constant.RELEASE);
                            }
                        }else {}
                        break;
                    case Constant.WAIT_SURVICE:
                        if(TAG!=Constant.LONG_HURRY){
                            if (i<3){
                                order.setForm_way(Constant.RELEASE);
                            }else {
                                order.setForm_way(Constant.BUY);
                            }
                        }else {
                            if (i<3){
                                order.setForm_way(Constant.RELEASE);
                            }else {
                                order.setForm_way(Constant.BUY);
                            }
                        }
                        break;
                    case Constant.IN_SURVICE:
                        if(TAG!=Constant.LONG_HURRY){
                            if (i<3){
                                order.setForm_way(Constant.RELEASE);
                                order.setIs_in_car(Constant.YES);
                            }else {
                                order.setForm_way(Constant.BUY);
                                order.setIs_in_car(Constant.NO);
                            }
                        }else {
                            if (i<2){
                                order.setIn_service_state(Constant.GOODS_ARRIVE);
                                order.setForm_way(Constant.RELEASE);
                            }else if (i>=2&&i<4){
                                order.setIn_service_state(Constant.GOODS_ARRIVE);
                                order.setForm_way(Constant.BUY);
                            }else if (i>=4&&i<6){
                                order.setIn_service_state(Constant.GOODS_IN_CAR);
                                order.setForm_way(Constant.RELEASE);

                            }else {
                                order.setIn_service_state(Constant.GOODS_IN_CAR);
                                order.setForm_way(Constant.BUY);

                            }
                        }
                        break;
                    case Constant.WAIT_FINISH:
                        if(TAG!=Constant.LONG_HURRY){
                            if (i<3){
                                order.setIs_finished(Constant.HOST_FINISHED_PASSENGER_NO);
                                order.setForm_way(Constant.RELEASE);
                            }else {
                                order.setForm_way(Constant.BUY);
                                order.setIs_finished(Constant.PASSENGER_FINISHED_HOST_NO);
                            }
                        }else {
                            if (i<2){
                                order.setWait_finish_state(Constant.WAIT_ME_FINISH);
                                order.setForm_way(Constant.RELEASE);
                            }else if (i>=2&&i<4){
                                order.setWait_finish_state(Constant.WAIT_ME_FINISH);
                                order.setForm_way(Constant.BUY);
                            }else if (i>=4&&i<6){
                                order.setWait_finish_state(Constant.WAIT_OTHER_FINISH);
                                order.setForm_way(Constant.RELEASE);
                            }else {
                                order.setWait_finish_state(Constant.WAIT_OTHER_FINISH);
                                order.setForm_way(Constant.BUY);
                            }
                        }
                        break;
                    case Constant.FINISHED:
                        if(TAG!=Constant.LONG_HURRY){
                            if (i<3){
                                order.setForm_way(Constant.RELEASE);
                            }else {
                                order.setForm_way(Constant.BUY);
                            }
                        }else {
                            if (i<3){
                                order.setForm_way(Constant.RELEASE);
                            }else {
                                order.setForm_way(Constant.BUY);
                            }
                        }
                        break;
                    case Constant.LOSS:
                        if(TAG!=Constant.LONG_HURRY){
                            if (i<3){
                                order.setForm_way(Constant.RELEASE);
                                order.setIs_return(Constant.YES);
                                order.setWho_return(Constant.ME);
                            }else {
                                order.setForm_way(Constant.BUY);
                                order.setIs_return(Constant.YES);
                                order.setWho_return(Constant.NOT_ME);
                            }
                        }else {
                            if (i<2){
                                order.setWho_return(Constant.ME);
                                order.setForm_way(Constant.RELEASE);
                            }else if (i>=2&&i<4){
                                order.setWait_finish_state(Constant.ME);
                                order.setForm_way(Constant.BUY);
                            }else if (i>=4&&i<6){
                                order.setWait_finish_state(Constant.NOT_ME);
                                order.setForm_way(Constant.RELEASE);
                            }else {
                                order.setWait_finish_state(Constant.NOT_ME);
                                order.setForm_way(Constant.BUY);
                            }
                        }
                        break;
                    case Constant.EXCEPTION:
                        if(TAG!=Constant.LONG_HURRY){
                            if (i<3){
                                order.setIs_reply(Constant.YES);
                                order.setForm_way(Constant.RELEASE);
                            }else {
                                order.setIs_reply(Constant.NO);
                                order.setForm_way(Constant.BUY);
                            }
                        }else {
                            if (i<2){
                                order.setIs_reply(Constant.YES);
                                order.setForm_way(Constant.RELEASE);
                            }else if (i>=2&&i<4){
                                order.setIs_reply(Constant.NO);
                                order.setForm_way(Constant.BUY);
                            }else if (i>=4&&i<6){
                                order.setIs_reply(Constant.YES);
                                order.setForm_way(Constant.RELEASE);
                            }else {
                                order.setIs_reply(Constant.NO);
                                order.setForm_way(Constant.BUY);
                            }
                        }
                        break;
                }
            }else if (identity==Constant.HOST){
                if (i<3){
                    order.setVehicle_type(Constant.BUS);
                }else {
                    order.setVehicle_type(Constant.PRIVATE_CAR);
                }
                switch (order_type){
                    case Constant.WAIT_PAY:
                        if(TAG!=Constant.LONG_HURRY){
                            if (i<3){
                                order.setIs_timeout(Constant.YES);
                            }else if (i>=3&&i<6){
                                order.setIs_timeout(Constant.NO);
                                order.setForm_way(Constant.RELEASE);
                                order.setIs_published(Constant.NO);
                                order.setIs_bought(Constant.YES);

                            }else {
                                order.setIs_timeout(Constant.NO);
                                order.setForm_way(Constant.BUY);
                                order.setIs_bought(Constant.NO);
                                order.setIs_published(Constant.YES);
                            }
                        }else {
                            if (i<3){
                                order.setIs_timeout(Constant.YES);
                            }else if (i>=3&&i<6){
                                order.setIs_timeout(Constant.NO);
                                order.setForm_way(Constant.RELEASE);
                            }else {
                                order.setForm_way(Constant.BUY);
                                order.setIs_bought(Constant.NO);
                            }
                        }
                        break;
                    case Constant.WAIT_TAKE:
                        if(TAG!=Constant.LONG_HURRY){
                            if (i<3){
                                order.setIs_timeout(Constant.YES);
                            }else if (i>=3&&i<6){
                                order.setIs_timeout(Constant.NO);
                                order.setIs_sale_start(Constant.YES);
                            }else {
                                order.setIs_timeout(Constant.NO);
                                order.setIs_sale_start(Constant.NO);
                            }
                        }else {

                        }
                        break;
                    case Constant.WAIT_SURVICE:
                        if(TAG!=Constant.LONG_HURRY){
                            if (i<3){
                                order.setForm_way(Constant.RELEASE);
                            }else {
                                order.setForm_way(Constant.BUY);
                            }
                        }else {

                        }
                        break;
                    case Constant.IN_SURVICE:
                        if(TAG!=Constant.LONG_HURRY){
                            if (i<3){
                                order.setForm_way(Constant.RELEASE);
                                order.setIs_in_car(Constant.YES);
                            }else {
                                order.setForm_way(Constant.BUY);
                                order.setIs_in_car(Constant.NO);
                            }
                        }else {

                        }
                        break;
                    case Constant.WAIT_FINISH:
                        if(TAG!=Constant.LONG_HURRY){
                            if (i<3){
                                order.setIs_finished(Constant.HOST_FINISHED_PASSENGER_NO);
                                order.setForm_way(Constant.RELEASE);
                            }else {
                                order.setForm_way(Constant.BUY);
                                order.setIs_finished(Constant.PASSENGER_FINISHED_HOST_NO);
                            }
                        }else {
                            if (i<3){
                                order.setIs_finished(Constant.HOST_FINISHED_PASSENGER_NO);
                            }else {
                               order.setIs_finished(Constant.PASSENGER_FINISHED_HOST_NO);
                            }
                        }
                        break;
                    case Constant.FINISHED:
                        if(TAG!=Constant.LONG_HURRY){
                            if (i<3){
                                order.setForm_way(Constant.RELEASE);
                            }else {
                                order.setForm_way(Constant.BUY);
                            }
                        }else {

                        }
                        break;
                    case Constant.LOSS:
                        if(TAG!=Constant.LONG_HURRY){
                            if (i<3){
                                order.setForm_way(Constant.RELEASE);
                                order.setIs_return(Constant.YES);
                                order.setWho_return(Constant.ME);
                            }else {
                                order.setForm_way(Constant.BUY);
                                order.setIs_return(Constant.YES);
                                order.setWho_return(Constant.NOT_ME);
                            }
                        }else {
                            if (i<3){
                                order.setWho_return(Constant.PASSENGER);
                            }else {
                                order.setWho_return(Constant.HOST);
                            }
                        }
                        break;
                    case Constant.EXCEPTION:
                        if(TAG!=Constant.LONG_HURRY){
                            if (i<3){
                                order.setIs_reply(Constant.YES);
                                order.setForm_way(Constant.RELEASE);
                            }else {
                                order.setIs_reply(Constant.NO);
                                order.setForm_way(Constant.BUY);
                            }
                        }else {

                        }
                        break;
                }
            }
            beanList.add(order);
        }
        adapter.notifyDataSetChanged();
        if (beanList.size()==0){
            rl_building.setVisibility(View.VISIBLE);
            refreshView.setVisibility(View.GONE);
        }else {
            rl_building.setVisibility(View.GONE);
            refreshView.setVisibility(View.VISIBLE);
        }
    }



    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (data!=null){
            int position = data.getIntExtra("position", -1);
            if (requestCode==Constant.REQUEST_CODE&&resultCode==Constant.RESULT_CANCEL_ORDER){//取消订单
                beanList.remove(position);
            }else if (requestCode==Constant.REQUEST_CODE&&resultCode==Constant.RESULT_START_SELL){//开始售票
                Order order = beanList.get(position);
                order.setIs_sale_start(Constant.YES);
                beanList.remove(position);
                beanList.add(position,order);
            }else if (requestCode==Constant.REQUEST_CODE&&resultCode==Constant.RESULT_END_SELL){//停止售票
                Order order = beanList.get(position);
                order.setIs_sale_start(Constant.NO);
                beanList.remove(position);
                beanList.add(position,order);
            }else if (requestCode==Constant.REQUEST_CODE&&resultCode==Constant.RESULT_ROUTE_FINISH_IN_SERVICE){//服务中行程完结
                beanList.remove(position);

            }else if (requestCode==Constant.REQUEST_CODE&&resultCode==Constant.RESULT_ROUTE_FINISH_WAIT_FINISH){//待完结行程完结
                beanList.remove(position);

            }else if (requestCode==Constant.REQUEST_CODE&&resultCode==Constant.RESULT_START_SERVICE){//开始服务
                beanList.remove(position);

            }else if (requestCode==Constant.REQUEST_CODE&&resultCode==Constant.RELULT_IN_CAR){//我已上车
                Order order = beanList.get(position);
                order.setIs_in_car(Constant.YES);
                beanList.remove(position);
                beanList.add(position,order);
            }else if (requestCode==Constant.REQUEST_CODE&&resultCode==Constant.RESULT_CANCEL_APPEAL){//取消申诉
                beanList.remove(position);
            }
            adapter.notifyDataSetChanged();
        }

    }
    private  void cancelAppealDialog(final String orderId, final String from){
        AlertDialog.Builder builder = null;
        builder = new AlertDialog.Builder(AppManager.getAppManager().currentActivity());
        View view = LayoutInflater.from(AppManager.getAppManager().currentActivity()).inflate(R.layout.dialog_layout, null);
        builder.setView(view);
        TextView cancel = (TextView) view.findViewById(R.id.dialog_cancel);
        TextView sure = (TextView) view.findViewById(R.id.dialog_sure);
        TextView message = (TextView) view.findViewById(R.id.dialog_text);
        sure.setText("确定");
        cancel.setText("取消");
        message.setText("您确定要取消申诉么？");
        final AlertDialog dialog = builder.create();
        cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });
        sure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                JSONObject object = new JSONObject();
                object.put("orderId",orderId);
                httpPost(getActivity(),Common.HOST+Common.CANCEL_APPEAL,object,from);
                dialog.dismiss();
            }
        });
        dialog.show();
    }

}
